package ui.juego.expedientes

import dominio.datos.Hobbie
import dominio.datos.Rasgo
import dominio.individuos.Villano
import dominio.investigacion.Expedientes
import java.awt.Color
import org.uqbar.arena.bindings.NotNullObservable
import org.uqbar.arena.bindings.PropertyAdapter
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner
import ui.juego.utilidades.IconUtils

abstract class ExpedientesWindow extends Dialog<Expedientes> {
	
	@Property int alturaListaVillanos
	
	new(WindowOwner parent, Expedientes model) {
		super(parent, model)
		title = "Expedientes"
		iconImage = IconUtils.path
	}
	
	override protected addActions(Panel actionsPanel) {}
	
	override protected createFormPanel(Panel mainPanel) {}
	
	override createMainTemplate(Panel mainPanel) {
		var contentPanel = new Panel(mainPanel) => [
			layout = new ColumnLayout(2)
		]
		
		var leftPanel = new Panel(contentPanel) => [
			layout = new VerticalLayout
		]
		
		crearPanelListadoVillanos(leftPanel)
		if (modelObject.conEdicion) crearPanelBotonera(leftPanel)
		crearPanelVillanoSeleccionado(contentPanel)
		
	}
	
	def crearPanelListadoVillanos(Panel owner) {
		var Panel panelListadoVillanos = new Panel(owner) => [
			layout = new VerticalLayout
		]	
		
		new Label(panelListadoVillanos)=> [
			text = "Villanos"
			foreground = Color.WHITE
			background = Color.GRAY
		]
		new List<Villano>(panelListadoVillanos) => [
			bindItemsToProperty("villanos").adapter = new PropertyAdapter(Villano, "nombre")
			heigth = alturaListaVillanos
			width = 100
			bindValueToProperty("villanoSeleccionado")
		]
	}
	
	def crearPanelBotonera(Panel owner) {
		var Panel botoneraPanel = new Panel(owner) => [
			layout = new VerticalLayout
		]

		var editar = new Button(botoneraPanel) => [
			caption = "Editar"
			width = 100
			onClick[ |
				val villano = modelObject.villanoSeleccionado
				new EdicionVillanoExistenteDialog(this, villano).open	
			]
		]

		new Button(botoneraPanel) => [
			caption = "Nuevo"
			width = 100
			onClick[ |
				new EdicionVillanoNuevoDialog(this, modelObject).open	
			]
		]

		var elementSelected = new NotNullObservable("villanoSeleccionado")
		editar.bindEnabled(elementSelected)
	}
	
	def crearPanelVillanoSeleccionado(Panel owner) {
		var infoVillanoPanel = new Panel(owner) => [
			layout = new VerticalLayout
		]
		
		new Label(infoVillanoPanel).text = "Nombre:"
		new Label(infoVillanoPanel) => [
			bindValueToProperty("villanoSeleccionado.nombre")
			fontSize = 14
			width = 100
		]
		
		new Panel(infoVillanoPanel) => [
			layout = new HorizontalLayout
			new Label(it).text = "Sexo:"
			new Label(it) => [
				bindValueToProperty("villanoSeleccionado.sexo")
				width = 100
			]
		]
		
		new Label(infoVillanoPanel) => [
			text = "Señas Particulares"
			foreground = Color.WHITE
			background = Color.GRAY
		]
		new List<Rasgo>(infoVillanoPanel) => [
			bindItemsToProperty("villanoSeleccionado.rasgos").adapter = new PropertyAdapter(Rasgo, "dato")
			heigth = 50
			width = 150
		]
		
		new Label(infoVillanoPanel) => [
			text = "Hobbies"
			foreground = Color.WHITE
			background = Color.GRAY
		]
		new List<Hobbie>(infoVillanoPanel) => [
			bindItemsToProperty("villanoSeleccionado.hobbies").adapter = new PropertyAdapter(Hobbie, "dato")
			heigth = 50
			width = 150
		]
		
	}

}